#pragma once

#include <QWidget>
#include "ui_MainWgt.h"
#include "MediaCtroller.h"
#include "api/video/video_sink_interface.h"
#include "api/video/video_frame.h"
#include <QHBoxLayout>
#include <QDebug>
#include "MediaCtroller.h"
#include <QPaintEvent>
#include <QPainter>
class Display :public QWidget {
	Q_OBJECT
public:
	Display(QWidget* parent) :QWidget(parent) {
		
	}
	void inputData(unsigned char*data,int width,int height) {
		m_image = QImage(data,width,height,QImage::Format_ARGB32);
		update();
	}
	void setPeerId(QString peerId)
	{
		m_peerId = peerId;
	}
	QString getPeerId()
	{
		return m_peerId;
	}
protected:
	void paintEvent(QPaintEvent* event) {
		QPainter painter(this);
		if (!m_image.isNull()){
			painter.drawImage(rect(), m_image);
		}
	}

private:
	QImage	m_image;
	QString m_peerId;
};


class MainWgt : public QWidget,public MediasoupEventCB
{
	Q_OBJECT

public:
	MainWgt(QWidget *parent = Q_NULLPTR);
	~MainWgt();
	void dataCallback(QString peerId,unsigned char*data,int width,int height);
	virtual void onNewPeer(QString peerId);
public Q_SLOTS:
	void onCreateCanvas(QString peerId);
private:
	Ui::MainWgt			ui;
	vi::MediaCtroller*	m_mediaCtrl;
	QHBoxLayout*		m_layout;
	QList<Display*>		m_peerList;
};
